package com.taoyibao.hongcanting.ui.mine.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.fragment.BaseListFragment;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.model.CouponModel;
import com.taoyibao.hongcanting.ui.home.activity.MenuActivity;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.zhy.adapter.recyclerview.base.ViewHolder;

/**
 * @author TangAnna
 * @description: 我的卡券 未使用
 * @date :${DATA} 16:55
 */
public class UnusedCouponFragment extends BaseListFragment<CouponModel> {
    private String mStatus;

    /**
     * @param status 优惠券的状态
     * @return
     */
    public static UnusedCouponFragment getInstance(String status) {
        Bundle bundle = new Bundle();
        bundle.putString(CodeConstant.STATUS, status);
        UnusedCouponFragment fragment = new UnusedCouponFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void bindItemData(ViewHolder holder, CouponModel couponModel, int position) {
        Button btn = holder.getView(R.id.btn_item_coupon_status);
        btn.setVisibility(View.VISIBLE);
        //设置优惠券状态
        if (TextUtils.equals(mStatus, CodeConstant.STATUS_UNUSED)) {
            btn.setEnabled(true);
            btn.setText(CodeUtils.getIdString(R.string.string_unused));
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    MenuActivity.open(getActivity());
                    getActivity().finish();
                }
            });
        } else if (TextUtils.equals(mStatus, CodeConstant.STATUS_EXPRIED)) {
            btn.setEnabled(false);
            btn.setText(CodeUtils.getIdString(R.string.string_expired));
        }
    }

    @Override
    public int bindItemView() {
        return R.layout.item_coupon;
    }

    @Override
    public void loadData() {
        mStatus = getArguments().getString(CodeConstant.STATUS);
        setEmptyView(true);
    }
}
